/*************************
评分等级
* */
<template>
  <div class="boxsty zhiBiao">

      <div :height="searchheight" v-loading.fullscreen.lock="fullscreenLoading">
      <span
        style="float: right; margin-top: -30px; cursor: pointer"
        @click="searchchangeadvanced"
      >{{ searchadvanced ? "收起" : "展开" }}
        <i
          :class="searchadvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
        />
      </span>
      <div v-show="searchadvanced">

          <el-form
            style="margin-bottom: unset"
            :inline="true"
            :model="scoreForm"
            :rules="dataRule"
            ref="scoreForm"
            class="form-inline" >
            <el-form-item label="评分规则">
              <el-select
                v-model="scoreForm.pfgz"
                placeholder="请选择评分规则"
                class="xiaLa"
                style="width: 100%"
                :clearable="true"
                @change="getFpgz"
              >
                <el-option
                  v-for="(item, index) in pfgzsList"
                  :key="index"
                  :label="item.name"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="占比规则" v-if="zbgz">
              A+<el-input type="text" v-model="scoreForm.ajsz" style="width:5%" max-length="10"></el-input>%
              A<el-input type="text" v-model="scoreForm.asz" style="width:5%" max-length="10"></el-input>%
              B<el-input type="text" v-model="scoreForm.bsz" style="width:5%" max-length="10"></el-input>%
              C<el-input type="text" v-model="scoreForm.csz" style="width:5%" max-length="10"></el-input>%
              D<el-input type="text" v-model="scoreForm.dsz" style="width:5%" max-length="10"></el-input>%
            </el-form-item>
            <el-form-item label="分数规则" v-if="fsgz">
              大于<el-input type="text" v-model="scoreForm.ajsz" style="width:5%" max-length="10"></el-input>A+
              大于<el-input type="text" v-model="scoreForm.asz" style="width:5%" max-length="10"></el-input>A
              大于<el-input type="text" v-model="scoreForm.bsz" style="width:5%" max-length="10"></el-input>B
              大于<el-input type="text" v-model="scoreForm.csz" style="width:5%" max-length="10"></el-input>C
              大于<el-input type="text" v-model="scoreForm.dsz" style="width:5%" max-length="10"></el-input>D
            </el-form-item>
          </el-form>


      <!--  <el-form  :model="searchForm" v-if="formVisible" class="form-inline" >
          <el-row>
            <el-col :span="24">
              <el-col :span="6">
                <el-form-item label="考核对象">
                  <el-input v-model="searchForm.khdx" placeholder="考核对象" :clearable="true" style="width:70%"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="工号">
                  <el-input v-model="searchForm.ygbm" placeholder="工号" :clearable="true" style="width:60%"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="11">
                <el-form-item>
                  <el-button
                    icon="el-icon-search"
                    type="primary"
                    class="marginLeft"
                    @click="getDataList(1)"
                  >检索</el-button>
                </el-form-item>
              </el-col>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="部门">
                <el-checkbox :indeterminate="isIndeterminateBm" v-model="checkAll"
                             @change="handleCheckAllChange" class="fla">全选</el-checkbox>
                <el-checkbox-group v-model="checkedBms" @change="handleCheckedBmsChange" class="fla">
                  <el-checkbox v-for="bms in bmsArr" :label="bms" :key="bms">{{bms}}</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="岗位">
                <el-checkbox :indeterminate="isIndeterminateGw" v-model="checkAllGw"
                             @change="handleCheckAllChangeGw" class="fla">全选</el-checkbox>
                <el-checkbox-group v-model="checkedGws" @change="handleCheckedGwsChange" class="fla">
                  <el-checkbox v-for="gws in gwsArr" :label="gws" :key="gws">{{gws}}</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-col>
          </el-row>

        </el-form>-->

      <div style="border-bottom: 1px solid #b0bde2">

      </div>
      <div class="mod-config" style="margin-top: 10px">

          <div class="pull-right" style="margin-bottom: 10px">
            <el-button
              type="primary"
              style="margin-left: 10px"
              plain
              v-if="editFlag ==0"
              @click="editFormData"
            >修改</el-button
            >

            <el-button
              type="primary"
              style="margin-left: 10px"
              plain
              v-if="editFlag ==1"
              @click="saveFormData"
            >确定</el-button
            >
            <el-button
              plain
              type="primary"
              style="margin-left: 10px"
              @click="fnBackOldPage('返回原页面')"
            >返回</el-button
            >
          </div>

        <div>
          <el-table
            style="width: 100%; margin-top: 20px"
            :data="dataList"
            border
            v-show="tabType == 1"
            v-loading="dataListLoading"
            @selection-change="handleSelectionChange"
            ref="table2"
          >
          <!--  <el-table-column type="selection" width="55" align="center"></el-table-column>-->
            <el-table-column
              type="index"
              width="80"
              header-align="center"
              align="center"
              label="序号"
            ></el-table-column>
            <el-table-column
              prop="ygbm"
              header-align="center"
              align="center"
              width="120"
              label="员工编号"
              show-overflow-tooltip
            >
              <!-- <template slot-scope="scope">
                 <el-input v-model="scope.row.ygbh" placeholder="员工编号" />
               </template>-->
            </el-table-column>

            <el-table-column
              prop="ygname"
              header-align="center"
              align="center"
              width="120"
              label="考核对象"
              show-overflow-tooltip
            >
              <!--  <template slot-scope="scope">
                  <el-input
                    v-model="scope.row.name"
                    placeholder="姓名"
                  />
                </template>-->
            </el-table-column>
            <el-table-column
              prop="deptName"
              header-align="center"
              align="center"
              width="120"
              label="部门"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              v-if="show"
              prop="deptId"
              header-align="center"
              align="center"
              label="部门id"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop="gwmc"
              header-align="center"
              align="center"
              width="120"
              label="岗位"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              v-if="show"
              prop="gwid"
              header-align="center"
              align="center"
              label="岗位id"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column align="center" label="测评">
              <el-table-column
                prop="cpScore"
                header-align="center"
                align="center"
                width="100"
                label="得分"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="cpQz"
                header-align="center"
                align="center"
                width="100"
                label="权重"
                show-overflow-tooltip
              >
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" label="日常考核">
              <el-table-column
                prop="rcScore"
                header-align="center"
                align="center"
                width="100"
                label="得分"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="rcQz"
                header-align="center"
                align="center"
                width="100"
                label="权重"
                show-overflow-tooltip
              >
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" label="业绩合同">
              <el-table-column
                prop="htScore"
                header-align="center"
                align="center"
                width="100"
                label="得分"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="htQz"
                header-align="center"
                align="center"
                width="100"
                label="权重"
                show-overflow-tooltip
              >
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" label="重点任务">
              <el-table-column
                prop="rwScore"
                header-align="center"
                align="center"
                width="100"
                label="得分"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="rwQz"
                header-align="center"
                align="center"
                width="100"
                label="权重"
                show-overflow-tooltip
              >
              </el-table-column>
            </el-table-column>
            <el-table-column align="center" label="工作任务书">
              <el-table-column
                prop="gzScore"
                header-align="center"
                align="center"
                width="100"
                label="得分"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="gzQz"
                header-align="center"
                align="center"
                width="100"
                label="权重"
                show-overflow-tooltip
              >
              </el-table-column>
            </el-table-column>
            <el-table-column
              prop="xs"
              header-align="center"
              align="center"
              width="120"
              label="系数"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop="jkfz"
              header-align="center"
              align="center"
              width="120"
              fixed="right"
              label="加扣分值"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.jkfz"
                  placeholder="加扣分值"
                  v-if="editFlag==1"
                  oninput="value=value.replace(/[^\-\d.]/g, '').replace(/^\./g, '').replace(/\.{2,}/g, '.').replace(/(\.\d+)\./g, '$1').replace(/(-)\./g, '$1').replace(/\-{2,}/g, '-').replace(/(\d+|\.)-/g, '$1').replace(/-(0){2,}/g, '$1').replace(/(-)0+(\d+)/g, '$1$2').replace(/^0+(\d)/, '$1').replace(/(\d{15})\d*/, '$1').replace(/(\.\d{2})\d*/, '$1')"
                  @blur="addJkfz(scope.row, scope.$index)"
                />
                <span
                  v-else
                >{{scope.row.jkfz}}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="zhdf"
              header-align="center"
              align="center"
              width="120"
              fixed="right"
              label="汇总得分"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop="zzdf"
              header-align="center"
              align="center"
              width="120"
              fixed="right"
              label="最终得分"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop="pfdj"
              header-align="center"
              align="center"
              width="140"
              fixed="right"
              label="评分等级"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <!--新增-->
                <el-select
                  v-model="scope.row.pfdj"
                  placeholder="请选择"
                  class="xiaLa"
                  style="width: 100%"
                  :clearable="true"
                  v-if="editFlag==1"
                >
                  <el-option
                    v-for="(item, index) in pfdjsList"
                    :key="index"
                    :label="item.name"
                    :value="item.value"
                  ></el-option>
                </el-select>
                <span v-else>{{scope.row.pfdj}}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
       <!-- <UserCommonSelect v-if="usercomment" ref="usercomment"  @refresh="refresh" :zid="zid"></UserCommonSelect>-->
      </div>


      </div>
      </div>
     <!-- <ScoreZxForm ref="eventzxRef" :scorezxForm="dataForm" :zid="zid"></ScoreZxForm>-->
<!--      子列表-->
     <!-- <span slot="footer" class="dialog-footer">
        <el-button type="primary" plain @click="closeDialog()">返回</el-button>
        <el-button  type="primary" plain @click="saveFormData">确定</el-button>
      </span>-->


  </div>
</template>

<script>

    // 接口 api
    import {
        getSysDeptDtoList,
        getGwmcDtoList,
        submitBmhzMx,
        submitGrade,
        getMxListQuery
    } from "@/api/statisticsanalysis/pfhzbmhzApi.js";
    // 接口 api
    import {
        getLdshMxListQuery,

    } from "@/api/statisticsanalysis/leaderApi.js";
    export default {
        components: {
           // UserCommonSelect
        },
        props: {
            dialogTitle: String
        },
        data() {

            return {
                editFlag : 0,
                formVisible:false,
                zbgz: false,
                fsgz: false,
                visible: false, //最外弹窗显隐
                searchadvanced: true,
                searchheight: "0",
                fullscreenLoading: false,
                searchForm:{},
                scoreForm:{
                },
                //dataForm:{},
                checkAll: false,
                checkedBms: [], // 初始选中的值
                bmsArr: [], //一共有多少个选项
                isIndeterminateBm: false, // 全选框是否在勾选状态

                checkAllGw: false,
                checkedGws: [], // 初始选中的值
                gwsArr: [], //一共有多少个选项
                isIndeterminateGw: false, // 全选框是否在勾选状态
                zid:'',
                tabType: "1",
                scorezxForm: {},
                usercomment: false, //人员选择显隐
                show:false,
                pageIndex: 1,
                pageSize: 10,
                totalPage: 0,
                type: 0,
                index: 1,
                dataList: [],
                dataListLoading: false,
                dialogVisible: false,
                pfgzsList : [
                    { name: "自由选择", value: "1" },
                    { name: "占比规则", value: "2" },
                    { name: "分数区间", value: "3" },
                ],
                pfdjsList : [
                  /*  { name: "A+", value: "A+" },
                    { name: "A", value: "A" },
                    { name: "B", value: "B" },
                    { name: "C", value: "C" },
                    { name: "D", value: "D" },*/
                ],
                dataRule: {
                    pfgz: [
                        {required: true, message: "请选择评分规则", trigger: "change"},
                    ],
                },
            }
        },
        watch: {},
        created() {

        },

        methods: {
            init(obj) {
                this.visible = true;
                this.zid = obj.id;
                this.getDataList();

                this.getSysDeptDtoList();//部门集合
                this.getGwmcDtoList();//岗位集合
                this.scoreForm = obj;
                if(obj.pfgz == null){

                    this.$set(this.scoreForm,'pfgz','1');

                }
                //this.$set(this.scoreForm,"pfgz",'');

                this.getfpgzbzList(obj);
                if(this.scoreForm.pfgz ==2){
                    this.zbgz = true;
                    this.fsgz = false;
                }
                if(this.scoreForm.pfgz ==3){
                    this.fsgz = true;
                    this.zbgz = false;
                }

            },
            getSysDeptDtoList(){
                this.bmsArr = [];
                getSysDeptDtoList(this.zid).then(res => {
                    res.data.data.map(it => {
                        this.bmsArr.push(it.deptName)
                    });

                });
            },
            getGwmcDtoList(){
                this.gwsArr = [];
                getGwmcDtoList(this.zid).then(res => {
                    res.data.data.map(it => {
                        this.gwsArr.push(it.gwmc)
                    });

                });

            },
            handleCheckAllChange(val) {
                this.checkedBms = val ? bms : [];
                this.isIndeterminateBm = false;

            },
            handleCheckedBmsChange(value) {
                let checkedCount = value.length;
                this.checkAll = checkedCount === this.bmsArr.length;
                this.isIndeterminateBm = checkedCount > 0 && checkedCount < this.bmsArr.length;
            },

            handleCheckAllChangeGw(val) {
                this.checkedGws = val ? gws : [];
                this.isIndeterminateGw = false;

            },
            handleCheckedGwsChange(value) {
                let checkedCount = value.length;
                this.checkAllGw = checkedCount === this.gwsArr.length;
                this.isIndeterminateGw = checkedCount > 0 && checkedCount < this.gwsArr.length;
            },
            // 勾选数据
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },

            selectSecondSelect(){
                //选择的时候强制刷新
                this.$forceUpdate()
            },
            getfpgzbzList(obj){

                let item1 = {
                    name: obj.ajszb,
                    value: obj.ajszb
                }
                this.pfdjsList.push(item1)

                let item2 = {
                    name: obj.aszb,
                    value: obj.aszb
                }
                this.pfdjsList.push(item2)

                let item3 = {
                    name: obj.bszb,
                    value: obj.bszb
                }
                this.pfdjsList.push(item3)

                let item4 = {
                    name: obj.cszb,
                    value: obj.cszb
                }
                this.pfdjsList.push(item4)

                let item5 = {
                    name: obj.dszb,
                    value: obj.dszb
                }
                this.pfdjsList.push(item5)

                let item6 = {
                    name: obj.eszb,
                    value: obj.eszb
                }
                this.pfdjsList.push(item6)

                let item7 = {
                    name: obj.fszb,
                    value: obj.fszb
                }
                this.pfdjsList.push(item7)



            },
            getFpgz(val){
                // 自由选择
                if(val == 1){
                    /*this.dataList.map(it =>{
                        let arr =  [
                            { name: "A+", value: "A+" },
                            { name: "A", value: "A" },
                            { name: "B", value: "B" },
                            { name: "C", value: "C" },
                            { name: "D", value: "D" },
                        ];
                      this.$set(it,"pfdjsList",arr);

                    })*/
                    this.zbgz = false;
                    this.fsgz = false;
                    this.$set(this.scoreForm,"ajsz","0");
                    this.$set(this.scoreForm,"asz","0");
                    this.$set(this.scoreForm,"bsz","0");
                    this.$set(this.scoreForm,"csz","0");
                    this.$set(this.scoreForm,"dsz","0");
                    this.$set(this.scoreForm,"esz","0");
                    this.$set(this.scoreForm,"fsz","0");
                }
                // 占比规则
                if(val == 2){

                    this.zbgz = true;
                    this.fsgz = false;
                    this.$set(this.scoreForm,"ajsz","0");
                    this.$set(this.scoreForm,"asz","0");
                    this.$set(this.scoreForm,"bsz","0");
                    this.$set(this.scoreForm,"csz","0");
                    this.$set(this.scoreForm,"dsz","0");
                    this.$set(this.scoreForm,"esz","0");
                    this.$set(this.scoreForm,"fsz","0");

                }
                // 分数区间
                if(val == 3){
                    this.fsgz = true;
                    this.zbgz = false;
                    this.$set(this.scoreForm,"ajsz","0");
                    this.$set(this.scoreForm,"asz","0");
                    this.$set(this.scoreForm,"bsz","0");
                    this.$set(this.scoreForm,"csz","0");
                    this.$set(this.scoreForm,"dsz","0");
                    this.$set(this.scoreForm,"esz","0");
                    this.$set(this.scoreForm,"fsz","0");

                }
            },
            addJkfz(row, index){
                let data = [];
                data = this.$refs.table2.selection;
                if(data.length != 0){
                    let  checked = [];
                    let  inputId = row.id;
                    data.map(ele => {
                        checked.push(ele.id);
                    });

                    data.map(it => {

                        if(checked.includes(inputId)){
                            it.jkfz = row.jkfz;
                            if(row.jkfz != null && row.jkfz != ""){
                                let zf = parseFloat(it.jkfz)+parseFloat(it.zhdf);

                                it.zzdf = this.numFilter(zf);

                            }

                        }


                    });
                }

                //两数组对象，获取不同的两数组对象

                let getArrayList = this.getArrDifSameValue(this.$refs.table2.selection,this.dataList)

                getArrayList.map(it => {
                    if(it.id == row.id){
                        if(row.jkfz != null && row.jkfz != ""){
                            let zf = parseFloat(it.jkfz)+parseFloat(it.zhdf);

                            it.zzdf = this.numFilter(zf);

                        }
                    }
                })

            },
            getArrDifSameValue(arr1,arr2){
                var result = [];
                for(var i = 0; i < arr2.length; i++){
                    var obj = arr2[i];
                    var id = obj.id;
                    var isExist = false;
                    for(var j = 0; j < arr1.length; j++){
                        var aj = arr1[j];
                        var n = aj.id;
                        if(n == id){
                            isExist = true;
                            break;
                        }
                    }
                    if(!isExist){
                        result.push(obj);
                    }
                }
                return result;
            },
            numFilter(value) {
                const realVal = parseFloat(value).toFixed(2);
                return realVal;
            },
            searchchangeadvanced() {
                this.searchadvanced = !this.searchadvanced;
                if (this.searchadvanced) {
                    this.searchheight = "auto";
                }
            },
            editFormData(){
                this.formVisible = true;
                this.editFlag = 1;
            },
            refresh(){//刷新
                this.getDataList();
            },
            //子组件列表
            getDataList() {
                this.dataListLoading = true;
                getLdshMxListQuery(
                    Object.assign(
                    {}
                   ),
                    this.zid
                    ).then(r => {

                    this.dataList = r.data.data;

                });
                this.dataListLoading = false;

            },
            // 每页数
            sizeChangeHandle(val) {
                this.pageSize = val;
                this.pageIndex = 1;
                this.getDataList();
            },
            // 当前页
            currentChangeHandle(val) {
                this.pageIndex = val;
                this.getDataList();
            },
            saveFormData() {
                this.$refs["scoreForm"].validate(valid => {
                    if (valid) {
                        if(this.scoreForm.pfgz == undefined){
                            this.$message.warning("请选择评分规则");
                            return false;
                        }else{
                            if(this.scoreForm.pfgz ==2){
                                let con = parseFloat(this.scoreForm.ajsz)+parseFloat(this.scoreForm.asz)+parseFloat(this.scoreForm.bsz)+parseFloat(this.scoreForm.csz)+parseFloat(this.scoreForm.dsz)+parseFloat(this.scoreForm.esz)+parseFloat(this.scoreForm.fsz);
                                if(con > 100){
                                    this.$message.warning("占比规则超100，请重新填写");
                                    return false;
                                }
                            }

                            this.scoreForm.bmhzMxList = this.dataList;

                            submitGrade(this.scoreForm).then(r => {
                                if (r.data.code == 0) {
                                    this.$message.success("保存成功");
                                    this.getDataList();
                                }
                            });

                        }

                    } else {
                        return false;
                    }
                });
             /*   submitBmhzMx(this.dataList,this.zid).then(r => {
                       if (r.data.code == 0) {
                           this.$message.success("保存成功");
                           this.getDataList();
                       }
                   });*/
            },

            //返回原来的页面
            fnBackOldPage(type) {
                this.$emit("fnBackOldPage", type);
            },
            closeDialog() {
                this.visible = false;
                this.$emit("closeDialog");
            }
        }

    };
</script>
<style lang="scss" scoped>
  .fla {
    float: left;
    margin-right: 15px !important;
    margin-left: 5px;
  }
</style>
